﻿using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkitMvvmDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CommunityToolkitMvvmDemo.ViewModels
{
    public class StudentViewModel: ObservableObject
    {
        private readonly Student model;

        public StudentViewModel(Student model) =>this.model = model;

        // Student 中的属性暴露出来
        public string Name
        {
            get=> model.Name;
            // T OldValue : 属性的当前值
            // T newValue: 属性的新值
            // Tmodel:正在包装的目标模型
            // Action<TModel，T>:如果属性的新值与当前属性不同，并且需要设置属性。由此回调函数完成。
            set =>SetProperty(model.Name, value , model, (model, value)=>model.Name= value);
        }
        public int Age
        {
            get =>model.Age;
            set =>SetProperty(model.Age, value , model, (model, age)=>model.Age= age);
        }
    }
}
